import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'meal_detail_page_content.dart';
import '../../../common/models/common_meal_model.dart';
import '../../../global/provider/favor_provider.dart';

class YSHMealDetailPage extends StatelessWidget {
  static const String routeName = '/mealDetailPage';
  const YSHMealDetailPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final mealModel =
    ModalRoute.of(context)?.settings.arguments as YSHCommonMealModel;
    return Scaffold(
      appBar: AppBar(
        title: Text(mealModel.title ?? ''),
      ),
      body: YSHMealDetailPageContent(mealModel),
      floatingActionButton: YSHMealDetailPageFloatingButton(mealModel),
    );
  }
}

class YSHMealDetailPageFloatingButton extends StatelessWidget {
  final YSHCommonMealModel _mealModel;
  const YSHMealDetailPageFloatingButton(this._mealModel, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Consumer<YSHFavorProvider>(
      builder: (ctx, favorProvider, child) {
        final iconData = favorProvider.isFavorMeal(_mealModel)
            ? Icons.favorite
            : Icons.favorite_border;
        return FloatingActionButton(
            onPressed: () {
              favorProvider.handleFavorMeal(_mealModel);
            },
            child: Icon(iconData, color: Colors.white));
      },
    );
  }
}